package com.ryskoo.catering.consumestatistics.repository;

import com.ryskoo.catering.consumestatistics.domain.ConsumeStatisticsPO;
import com.ryskoo.framework.core.bean.QueryConditionEnum;
import com.ryskoo.framework.core.bean.QueryMessageDTO;
import com.ryskoo.framework.core.repository.BasicJPAImpl;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class ConsumeStatisticsJPAImpl extends BasicJPAImpl<ConsumeStatisticsPO> implements IConsumeStatisticsRepository {

    @Override
    public ConsumeStatisticsPO getByVendorAndCustomer(String vendorUuid, String customerUuid) {
        QueryMessageDTO qm = new QueryMessageDTO();
        qm.addCondition("vendorUuid", QueryConditionEnum.EQ.name(), vendorUuid);
        qm.addCondition("customerUuid", QueryConditionEnum.EQ.name(), customerUuid);
        List<ConsumeStatisticsPO> list = queryByCondition(qm, false);
        if(CollectionUtils.isNotEmpty(list)){
            return list.get(0);
        }
        return null;
    }
}
